package com.hongning.railway.ui.main.mine.experience;


import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.app.AppViewModelFactory;
import com.hongning.railway.databinding.FragmentExperienceBinding;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.ToastUtils;

/**
 * 心得体会
 */
public class ExperienceFragment extends BaseFragment<FragmentExperienceBinding,ExperienceFragmentViewModel> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_experience;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        binding.appTitle.ivRight.setVisibility(View.VISIBLE);
        binding.appTitle.ivRight.setImageResource(R.mipmap.icon_edit);
        binding.appTitle.ivRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewModel.startContainerActivity(ExperiencePubOrEditFragment.class.getCanonicalName());
            }
        });
        binding.rvContent.setItemAnimator(null);
        binding.appTitle.tvTopTitle.setText("心得体会");
        binding.appTitle.ivLeft.setVisibility(View.VISIBLE);
        binding.appTitle.ivLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        viewModel.loadData();
    }

    @Override
    public ExperienceFragmentViewModel initViewModel() {
        AppViewModelFactory appViewModelFactory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this,appViewModelFactory).get(ExperienceFragmentViewModel.class);
    }
}
